package edu.wust;

import java.io.*;
import java.math.BigInteger;

public class exam56 {
    public static int num(int a,int b){
        BigInteger end=BigInteger.ONE,t=new BigInteger(String.valueOf(a));
        for(int i=0;i<b;i++){
            end=end.multiply(t);
        }
        String s=end.toString();
        int len=s.length(),sum=0;
        for(int i=0;i<len;++i)
            sum+=s.charAt(i)-'0';
        return sum;
    }
    public static void main(String[] args) throws IOException {
        int max=0;
        for(int i=1;i<100;++i){
            for(int j=1;j<100;++j){
                max=Math.max(max,num(i,j));
            }
        }
        System.out.println(max);
    }
}


